﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Buyer
{
    public partial class mfCommentOrder : msBsc.Cls.mbPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void addComments()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("评论订单不能为空");
                return;
            }
            string paroductId = this.GetParamHtValue("paroductId");
            if (string.IsNullOrEmpty(paroductId))
            {
                this.Alert("评论车辆不能为空");
                return;
            }
            string Comments = this.GetParamHtValue("Comments");
            if (string.IsNullOrEmpty(Comments))
            {
                this.Alert("评论内容不能为空");
                return;
            }
            string reviewP1 = this.GetParamHtValue("reviewP1");
            string reviewP1Name = this.GetParamHtValue("reviewP1Name");
            string reviewP2 = this.GetParamHtValue("reviewP2");
            string reviewP2Name = this.GetParamHtValue("reviewP2Name");
            string reviewP3 = this.GetParamHtValue("reviewP3");
            string reviewP3Name = this.GetParamHtValue("reviewP3Name");
            string reviewP4 = this.GetParamHtValue("reviewP4");
            string reviewP4Name = this.GetParamHtValue("reviewP4Name");
            string reviewP5 = this.GetParamHtValue("reviewP4");
            string reviewP5Name = this.GetParamHtValue("reviewP5Name");
            List<string> listStr = new List<string>();
            using (msBsc.AppLogic.DataAlc.CBizSysFile sysFile = new AppLogic.DataAlc.CBizSysFile())
            {
                bool blfnmeutf8 = true;
                if (reviewP1.IndexOf(";base64") > -1)
                {
                    reviewP1 = reviewP1.Split(',')[1];
                    reviewP1 = sysFile.SaveBase64ImgServer(reviewP1, reviewP1Name, blfnmeutf8);
                    listStr.Add(reviewP1);
                }
                if (reviewP2.IndexOf(";base64") > -1)
                {
                    reviewP2 = reviewP2.Split(',')[1];
                    reviewP2 = sysFile.SaveBase64ImgServer(reviewP2, reviewP2Name, blfnmeutf8);
                    listStr.Add(reviewP2);
                }
                if (reviewP3.IndexOf(";base64") > -1)
                {
                    reviewP3 = reviewP3.Split(',')[1];
                    reviewP3 = sysFile.SaveBase64ImgServer(reviewP3, reviewP3Name, blfnmeutf8);
                    listStr.Add(reviewP3);
                }
                if (reviewP4.IndexOf(";base64") > -1)
                {
                    reviewP4 = reviewP4.Split(',')[1];
                    reviewP4 = sysFile.SaveBase64ImgServer(reviewP4, reviewP4Name, blfnmeutf8);
                    listStr.Add(reviewP4);
                }
                if (reviewP5.IndexOf(";base64") > -1)
                {
                    reviewP5 = reviewP5.Split(',')[1];
                    reviewP5 = sysFile.SaveBase64ImgServer(reviewP5, reviewP5Name, blfnmeutf8);
                    listStr.Add(reviewP5);
                }
            }
            string[] images = new string[listStr.Count];
            for (int i = 0; i < listStr.Count; i++)
            {
                images[i] = listStr[i];
            }
            //添加评论信息
            using (msBsc.AppLogic.DataAlc.CBizCustomerEvlution CBEComments = new AppLogic.DataAlc.CBizCustomerEvlution())
            {
                string ms = CBEComments.AddCustomerEvlution(orderId, paroductId, Comments, images);
                if (ms != "OK")
                {
                    this.Alert(ms);
                }
                else
                {
                    this.ExecJScript("alert('评论成功');window.location.href = '/mb_OrderInfo.htm?orderId="+orderId+"'");
                }
                //this.ExecJScript(@"layer.alert('" + ms + "', 3);");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "addComments")
            {
                addComments();
            }
        }
    }
}